/**
 * 载信软件(上海)有限公司
 * Copyright (c) 2015-2024 B5M,Inc.All Rights Reserved.
 */
package com.sys.midware.assist.utils;

public abstract class Assert {
	/**
	 *  Assert a boolean expression, throwing {@code IllegalArgumentException}
	 * @param expression
	 * @param message
	 */
	public static void isTrue(boolean expression, String message) {
		if (!expression) {
			throw new IllegalArgumentException(message);
		}
	}
	/**
	 * Assert a boolean expression, throwing {@code IllegalArgumentException}
	 * @param expression
	 */
	public static void isTrue(boolean expression) {
		isTrue(expression, "[Assertion failed] - this expression must be true");
	}
	/**
	 * Assert that an object is {@code null} .
	 * @param object
	 * @param message
	 */
	public static void isNull(Object object, String message) {
		if (object != null) {
			throw new IllegalArgumentException(message);
		}
	}
	/**
	 * Assert that an object is {@code null} .
	 * @param object
	 */
	public static void isNull(Object... object ) {
		for (Object obj : object)
		{
			isNull(obj, "[Assertion failed] - the object argument must be null");
		}
	}
	/**
	 * Assert that an object is not {@code null} .
	 * @param object
	 * @param message
	 */
	public static void notNull(Object object, String message) {
		if (object == null) {
			throw new IllegalArgumentException(message);
		}
	}
	/**
	 * Assert that an object is not {@code null} .
	 * @param object
	 */
	public static void notNull(Object object) {
		notNull(object, "[Assertion failed] - this argument is required; it must not be null");
	}
	
	   /**
     * Assert that an object is not {@code null} .
     * @param object
     */
    public static void notNull(Object... object) {
        for (Object obj : object)
        {
            notNull(obj);
        }
    }
	
	/**
	 * Assert that an array has elements; that is, it must not be
	 * {@code null} and must have at least one element.
	 * @param array
	 * @param message
	 */
//	public static void notEmpty(Object[] array, String message) {
//		if (ObjectUtils.isEmpty(array)) {
//			throw new IllegalArgumentException(message);
//		}
//	}
//	/**
//	* Assert that an array has elements; that is, it must not be
//	 * {@code null} and must have at least one element.
//	 * @param array
//	 */
//	public static void notEmpty(Object[] array) {
//		notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
//	}
	/**
	 * Assert that an array has no null elements.
	 * @param array
	 * @param message
	 */
	public static void noNullElements(Object[] array, String message) {
		if (array != null) {
			for (Object element : array) {
				if (element == null) {
					throw new IllegalArgumentException(message);
				}
			}
		}
	}
	/**
	 * Assert that an array has no null elements.
	 * @param array
	 * @param message
	 */
	public static void noNullElements(Object[] array) {
		noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
	}
	/**
	 * Assert that the provided object is an instance of the provided class.
	 * @param clazz
	 * @param obj
	 */
//	public static void isInstanceOf(Class<?> clazz, Object obj) {
//		isInstanceOf(clazz, obj, "");
//	}
	/**
	 * Assert that the provided object is an instance of the provided class.
	 * @param clazz
	 * @param obj
	 */
//	public static void isInstanceOf(Class<?> type, Object obj, String message) {
//		notNull(type, "Type to check against must not be null");
//		if (!type.isInstance(obj)) {
//			throw new IllegalArgumentException(
//					(StringUtils.hasLength(message) ? message + " " : "") +
//					"Object of class [" + (obj != null ? obj.getClass().getName() : "null") +
//					"] must be an instance of " + type);
//		}
//	}
	/**
	 * Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
	 * @param superType
	 * @param subType
	 */
	public static void isAssignable(Class<?> superType, Class<?> subType) {
		isAssignable(superType, subType, "");
	}
	/**
	 * Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
	 * @param superType
	 * @param subType
	 */
	public static void isAssignable(Class<?> superType, Class<?> subType, String message) {
		notNull(superType, "Type to check against must not be null");
		if (subType == null || !superType.isAssignableFrom(subType)) {
			throw new IllegalArgumentException(message + subType + " is not assignable to " + superType);
		}
	}
	/**
	 * Assert a boolean expression, throwing {@code IllegalStateException}
	 * if the test result is {@code false}. Call isTrue if you wish to
	 * throw IllegalArgumentException on an assertion failure.
	 *<pre class="code">Assert.state(id == null, "The id property must not already be initialized");</pre>
	 * @param expression a boolean expression
	 * @param message the exception message to use if the assertion fails
	 * @throws IllegalStateException if expression is {@code false}
	 */
	public static void state(boolean expression, String message) {
		if (!expression) {
			throw new IllegalStateException(message);
		}
	}
	/**
	 * Assert a boolean expression, throwing {@code IllegalStateException}
	 * if the test result is {@code false}. Call isTrue if you wish to
	 * throw IllegalArgumentException on an assertion failure.
	 *<pre class="code">Assert.state(id == null, "The id property must not already be initialized");</pre>
	 * @param expression a boolean expression
	 * @param message the exception message to use if the assertion fails
	 * @throws IllegalStateException if expression is {@code false}
	 */
	public static void state(boolean expression) {
		state(expression, "[Assertion failed] - this state invariant must be true");
	}
	
	  public static void notNegative(Number value)
	  {
	    notNull(value);
	    if (value.doubleValue() < 0.0D)
	      throw new RuntimeException("negative");
	  }

}
